Ext.define('Admin.view.competitive.NegotiationController', {

	extend: 'Admin.ux.GridController',

	alias: 'controller.competitive',

	moreAction: function (grid, rowIndex, colIndex, item, e, record, row) {

		var rec = grid.getStore().getAt(rowIndex);

		var me = this;

		var treeMenu = new Ext.menu.Menu({
			shadow: "drop",
			allowOtherMenus: true,
			items: [
				new Ext.menu.Item({
					text: "编辑",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						var win = Ext.create("Admin.ux.Window", {
							title: '编辑竞谈公告',
							width: 900,
							height: 700,
							animateTarget: row,
							items: { xtype: 'negotiation-edit' },
							buttons: [
								{
									text: '保存',
									ui: 'soft-green',
									iconCls: 'x-fa 	fa-floppy-o',
									handler: function (btn) {
										var form = btn.up("window").down("form").getForm();
										Ext.create('Admin.ux.Action').submit(form, '/tender/edit', me.getView(), win);
									}
								},
								{
									text: '重置',
									ui: 'soft-red',
									iconCls: 'x-fa 	fa-mail-reply',
									handler: function (btn) {
										var form = btn.up("window").down("form");
										form.getForm().load({
											url: '/tender/get',
											waitMsg: '加载中...',
											params: {
												id: rec.get('id')
											},
											success: function () {
												form.down('textfield[id=id]').setReadOnly(true);
											},
											failure: function (form, action) {
												if (action.result.msg != undefined) {
													Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
												} else {
													Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
												}
											}
										});
										form.loadRecord(rec);
									}
								},
								{
									text: '取消',
									ui: 'gray',
									iconCls: 'x-fa 	fa-ban',
									handler: function (btn) {
										btn.up("window").close();
									}
								}
							],

							listeners: {
								show: function (w, opts) {

									var form = this.down('form');

									form.getForm().load({
										url: '/tender/get',
										waitMsg: '加载中...',
										params: {
											id: rec.get('id')
										},
										success: function () {
											form.down('textfield[id=id]').setReadOnly(true);
										},
										failure: function (form, action) {
											if (action.result.msg != undefined) {
												Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
											} else {
												Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
											}
										}
									});
								}
							}
						});
					}
				}),
				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "查看",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						//自行修改
						window.open("http://140.143.121.69/TenderWeb/ControlView/_ViewNotice?id=" + rec.get('id'));
					}
				}),
				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "发布二次公告",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						var win = Ext.create("Admin.ux.Window", {
							title: '发布二次公告',
							width: 900,
							height: 700,
							animateTarget: row,
							items: { xtype: 'negotiation-edit' },
							buttons: [
								{
									text: '保存',
									ui: 'soft-green',
									iconCls: 'x-fa 	fa-floppy-o',
									handler: function (btn) {
										var form = btn.up("window").down("form").getForm();
										Ext.create('Admin.ux.Action').submit(form, '/tender/edit', me.getView(), win);
									}
								},
								{
									text: '重置',
									ui: 'soft-red',
									iconCls: 'x-fa 	fa-mail-reply',
									handler: function (btn) {
										var form = btn.up("window").down("form");
										form.getForm().load({
											url: '/tender/get',
											waitMsg: '加载中...',
											params: {
												id: rec.get('id')
											},
											success: function () {
												form.down('textfield[id=id]').setReadOnly(true);
											},
											failure: function (form, action) {
												if (action.result.msg != undefined) {
													Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
												} else {
													Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
												}
											}
										});
										form.loadRecord(rec);
									}
								},
								{
									text: '取消',
									ui: 'gray',
									iconCls: 'x-fa 	fa-ban',
									handler: function (btn) {
										btn.up("window").close();
									}
								}
							],

							listeners: {
								show: function (w, opts) {

									var form = this.down('form');

									form.getForm().load({
										url: '/tender/get',
										waitMsg: '加载中...',
										params: {
											id: rec.get('id')
										},
										success: function () {
											form.down('textfield[id=id]').setReadOnly(true);
										},
										failure: function (form, action) {
											if (action.result.msg != undefined) {
												Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
											} else {
												Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
											}
										}
									});
								}
							}
						});
					}
				}),
				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "发布变更",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						var win = Ext.create("Admin.ux.Window", {
							title: '发布变更',
							width: 900,
							height: 700,
							animateTarget: row,
							items: { xtype: 'negotiation-edit' },
							buttons: [
								{
									text: '保存',
									ui: 'soft-green',
									iconCls: 'x-fa 	fa-floppy-o',
									handler: function (btn) {
										var form = btn.up("window").down("form").getForm();
										Ext.create('Admin.ux.Action').submit(form, '/tender/edit', me.getView(), win);
									}
								},
								{
									text: '重置',
									ui: 'soft-red',
									iconCls: 'x-fa 	fa-mail-reply',
									handler: function (btn) {
										var form = btn.up("window").down("form");
										form.getForm().load({
											url: '/tender/get',
											waitMsg: '加载中...',
											params: {
												id: rec.get('id')
											},
											success: function () {
												form.down('textfield[id=id]').setReadOnly(true);
											},
											failure: function (form, action) {
												if (action.result.msg != undefined) {
													Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
												} else {
													Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
												}
											}
										});
										form.loadRecord(rec);
									}
								},
								{
									text: '取消',
									ui: 'gray',
									iconCls: 'x-fa 	fa-ban',
									handler: function (btn) {
										btn.up("window").close();
									}
								}
							],

							listeners: {
								show: function (w, opts) {

									var form = this.down('form');

									form.getForm().load({
										url: '/tender/get',
										waitMsg: '加载中...',
										params: {
											id: rec.get('id')
										},
										success: function () {
											form.down('textfield[id=id]').setReadOnly(true);
										},
										failure: function (form, action) {
											if (action.result.msg != undefined) {
												Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
											} else {
												Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
											}
										}
									});
								}
							}
						});
					}
				}),
				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "发布竞谈结果公示",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						var win = Ext.create("Admin.ux.Window", {
							title: '发布竞谈结果公示',
							width: 900,
							height: 700,
							animateTarget: row,
							items: { xtype: 'negotiation-edit' },
							buttons: [
								{
									text: '保存',
									ui: 'soft-green',
									iconCls: 'x-fa 	fa-floppy-o',
									handler: function (btn) {
										var form = btn.up("window").down("form").getForm();
										Ext.create('Admin.ux.Action').submit(form, '/tender/edit', me.getView(), win);
									}
								},
								{
									text: '重置',
									ui: 'soft-red',
									iconCls: 'x-fa 	fa-mail-reply',
									handler: function (btn) {
										var form = btn.up("window").down("form");
										form.getForm().load({
											url: '/tender/get',
											waitMsg: '加载中...',
											params: {
												id: rec.get('id')
											},
											success: function () {
												form.down('textfield[id=id]').setReadOnly(true);
											},
											failure: function (form, action) {
												if (action.result.msg != undefined) {
													Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
												} else {
													Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
												}
											}
										});
										form.loadRecord(rec);
									}
								},
								{
									text: '取消',
									ui: 'gray',
									iconCls: 'x-fa 	fa-ban',
									handler: function (btn) {
										btn.up("window").close();
									}
								}
							],

							listeners: {
								show: function (w, opts) {

									var form = this.down('form');

									form.getForm().load({
										url: '/tender/get',
										waitMsg: '加载中...',
										params: {
											id: rec.get('id')
										},
										success: function () {
											form.down('textfield[id=id]').setReadOnly(true);
										},
										failure: function (form, action) {
											if (action.result.msg != undefined) {
												Ext.Msg.alert("提示", "<font color=red>" + action.result.msg + "!</font>");
											} else {
												Ext.Msg.alert("提示", "<font color=red>加载出错,请刷新页面重试!</font>");
											}
										}
									});
								}
							}
						});
					}
				}),
				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "查看报名情况",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						//自行修改
						window.open("http://140.143.121.69/TenderWeb/ControlView/_ViewNotice?id=" + rec.get('id'));
					}
				}),

				new Ext.menu.Separator(),
				new Ext.menu.Item({
					text: "删除",
					iconCls: 'array-grid-buy-col',
					handler: function () {
						Ext.MessageBox.confirm('系统提示', '确认要删除选中记录么？', function (btn) {
							if (btn !== 'yes') {
								return;
							}

							Ext.Ajax.request({
								method: 'DELETE',
								url: '/tender/get?id=' + rec.get('id'),

								success: function (response) {
									grid.getStore().loadPage(1);
									Ext.Msg.alert('系统提示', '删除成功！');
								},

								failure: function (response) {
									Ext.Msg.alert('系统提示', '删除失败!');
								}
							});
						})
					}
				})
			]
		});
		treeMenu.showAt(e.getPoint());
	},

	addAction: function (b) {
		var me = this;
		var win = Ext.create("Admin.ux.Window", {
			width: 900,
			height: 700,
			animateTarget: b,
			items: { xtype: 'negotiation-edit' },
			buttons: [
				{
					text: '保存',
					ui: 'soft-green',
					iconCls: 'x-fa 	fa-floppy-o',
					handler: function (btn) {
						var form = btn.up("window").down("form").getForm();
						Ext.create('Admin.ux.Action').submit(form, '/tender/sectionAdd', me.getView(), win);
					}
				},
				{
					text: '重置',
					ui: 'soft-red',
					iconCls: 'x-fa 	fa-mail-reply',
					handler: function (btn) {
						btn.up("window").down("form").reset();
					}
				},
				{
					text: '取消',
					ui: 'gray',
					iconCls: 'x-fa 	fa-ban',
					handler: function (btn) {
						btn.up("window").close();
					}
				}
			]
		});
	}

});